<?php
/**
 * Created by a front-end programmer.
 * User: Xwen
 * Date: 2018/2/26
 * Time: 9:46
 * Mail:lauwencn@gmail.com
 */
class CategoryController extends CommonController{
    private $_model = NULL;
    public function __auto(){
        $this->_model = K('Category');
    }
    public function add(){
        if(IS_POST){
            $this->_model->add_data();
            $this->success('添加成功', __APP__.'?c=Category&m=index');
        }
        $this->display();
    }
    public function index(){
        $data = $this->_model->get_all();
        $this->assign('data', $data);
        $this->display();
    }
    public function del(){
        $cid = (int)$_GET['cid'];
        $this->_model->remove($cid);
        $this->success('删除成功');
    }
    public function update(){
        if(IS_POST){
            $cid = (int)$_POST['cid'];
            $this->_model->edit($cid);
            $this->success('修改成功', __APP__.'?c=Category&m=index');
        }
        $cid = (int)$_GET['cid'];
        $oldData = $this->_model->get_one($cid);
        $this->assign('oldData', $oldData);
        $this->display();
    }
}

?>